package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Publish;
import com.tanhua.server.service.MovementsMqService;
import com.tanhua.server.service.MovementsService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;

@RestController
@RequestMapping("/movements")
public class MovementsController {

    @Autowired
    private MovementsService movementsService;
    @Autowired
    private MovementsMqService movementsMqService;

    @GetMapping(value = "/visitors",name = "最近谁看过我")
    public ResponseEntity visitors(){
        return movementsService.queryVisitors();
    }


    @PostMapping(name = "发布圈子动态数据")
//    Publish publish前面千万不要加@RequestBody
    public ResponseEntity saveMovements(Publish publish, MultipartFile[] imageContent) throws Exception{
        return  movementsService.saveMovements(publish,imageContent);
    }

    @GetMapping(name = "查询好友的圈子动态")
    public ResponseEntity queryFriendMovements(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")  Integer pagesize) throws Exception{
        return  movementsService.queryFriendMovements(page,pagesize);
    }

    @GetMapping(value = "/recommend",name = "查询推荐的圈子动态")
    public ResponseEntity queryRecommendMovements(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")  Integer pagesize) throws Exception{
        return  movementsService.queryRecommendMovements(page,pagesize);
    }

    @GetMapping(value = "/all",name = "分页查询指定用户发布的圈子动态")
    public ResponseEntity queryMySelfMovements(
            @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")  Integer pagesize,
            Long userId
    ) throws Exception{
        return  movementsService.queryMySelfMovements(page,pagesize,userId);
    }


    @GetMapping(value = "/{id}/like",name = "对圈子动态点赞")
    public ResponseEntity likeComment(@PathVariable("id") String publishId) throws Exception{
//        评论内容类型： 1-对圈子动态操作 2-对视频操作 3-对评论操作
        movementsMqService.sendMsg(publishId,2);
        return  movementsService.likeComment(publishId,1);
    }
    @GetMapping(value = "/{id}/dislike",name = "对圈子动态取消点赞")
    public ResponseEntity dislikeComment(@PathVariable("id") String publishId) throws Exception{
//        评论内容类型： 1-对圈子动态操作 2-对视频操作 3-对评论操作
        movementsMqService.sendMsg(publishId,5);
        return  movementsService.dislikeComment(publishId,1);
    }
    @GetMapping(value = "/{id}/love",name = "对圈子动态喜欢")
    public ResponseEntity loveComment(@PathVariable("id") String publishId) throws Exception{
//        评论内容类型： 1-对圈子动态操作 2-对视频操作 3-对评论操作
        movementsMqService.sendMsg(publishId,3);
        return  movementsService.loveComment(publishId,1);
    }
    @GetMapping(value = "/{id}/unlove",name = "对圈子动态取消喜欢")
    public ResponseEntity unloveComment(@PathVariable("id") String publishId) throws Exception{
//        评论内容类型： 1-对圈子动态操作 2-对视频操作 3-对评论操作
        movementsMqService.sendMsg(publishId,6);
        return  movementsService.unloveComment(publishId,1);
    }
    @GetMapping(value = "/{id}",name = "根据id获取圈子动态")
    public ResponseEntity queryMovementsById(@PathVariable("id") String publishId) throws Exception{
        movementsMqService.sendMsg(publishId,1);
        return  movementsService.queryMovementsById(publishId);
    }


}
